<?php

function cpost($url, $post) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1');
  curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($ch);
  curl_close($ch);
  return $result;
}

function surl($content , $sid, $qq, $ua, $richval, $lon = "", $lat = "") {
  $url = 'http://m.qzone.com/mood/publish_mood';
  $post = 'content='.$content.'++&sid='.$sid.'&lon='.$lon.'&lbsid=&res_uin='.$qq.'&richval='.urlencode($richval).'&source_name='.$ua.'&is_winphone=2&opr_type=publish_shuoshuo&format=json&issyncweibo=0&lat='.$lat;
  return cpost($url, $post);
}

if( !ini_get('safe_mode')){
set_time_limit(0);
}else{
ini_set('max_execution_time',10000);
}
require'connect.php';
$qqselect_sql="select * from qqlist where ss>1";
$qqselect_result=mysql_query($qqselect_sql);
while($array=mysql_fetch_array($qqselect_result)){
$qq=$array['qq'];
$sid=$array['sid'];
$ss=$array['ss'];
$ua=$array['ssua'];
$zdss=$array['zdss'];
$sscs=$array['sscs'];
$sswb=$array['sswb'];

if($sscs>=$zdss)
{
if($ua=='随机')
{
$nr=file('ssua.txt');
shuffle($nr);
$ua=''.$nr['0'].'';
}


if($ss=='2'){
$nr=file('ss.txt');
shuffle($nr);
$content=$nr['0'];
}
if($ss=='3'){
$file=file_get_contents("tupian.txt");
$ex=explode("+++",$file);
$n=$ex[rand(0,count($ex)-1)];
$nr=explode("---",$n);
$content=$nr['0'];
$picurl=$nr[1];
}
$content=$content.$sswb;



  if ((!empty($sid)) && (!empty($qq))) {
    $file = $picurl;
    $image_size = getimagesize($file);
    $image = file_get_contents($file);
    $url = "http://up.qzone.com/cgi-bin/upload/cgi_upload_pic_v2";
    $post = "picture=".urlencode(base64_encode($image))."&base64=1&hd_height=".$image_size[1]."&hd_width=".$image_size[0]."&hd_quality=90&output_type=json&preupload=1&charset=utf-8&output_charset=utf-8&logintype=sid&Exif_CameraMaker=&Exif_CameraModel=&Exif_Time=&uin=".$qq."&sid=".$sid;
    $data = preg_replace("/\s/", "", cpost($url, $post));
    preg_match('/_Callback\((.*)\);/', $data, $arr);
    $data = json_decode($arr[1], true);
    $post = "output_type=json&preupload=2&md5=".$data[filemd5]."&filelen=".$data[filelen]."&batchid=".time().rand(100000, 999999)."&currnum=0&uploadNum=1&uploadtime=".time()."&uploadtype=1&upload_hd=0&albumtype=7&big_style=1&op_src=15003&charset=utf-8&output_charset=utf-8&uin=".$qq."&sid=".$sid."&logintype=sid&refer=shuoshuo";
    $img = preg_replace("/\s/", "", cpost($url, $post));
    preg_match('/_Callback\(\[(.*)\]\);/', $img, $arr);
    $data = json_decode($arr[1], true);
    $richval = ($data[picinfo][albumid] != "") ? "{$data[picinfo][albumid]},{$data[picinfo][lloc]},{$data[picinfo][sloc]},{$data[picinfo][type]},{$data[picinfo][height]},{$data[picinfo][width]},,,": "";
    $result = surl($content, $sid, $qq, $ua, $richval, $lon, $lat);
    $result = json_decode($result, true);
    if ($result[code] == 0) echo "";
  }

$xiugai_sql="update qqlist set sscs='1' where qq=$qq";
if(mysql_query($xiugai_sql))
{
echo '次数归1一条<br>';
}
}
if($sscs<$zdss)
{
$sscs=$sscs+1;
$xiugai_sql="update qqlist set sscs='$sscs' where qq=$qq";
if(mysql_query($xiugai_sql))
{
echo '次数加1一条<br>';
}
}
}
?>